Debugging software that runs before the system gets properly initialised can be
a pain. There are a few methods. They range in convenience and complexity, so
each has its place:

The first thing you'll most likely want to do is get a statically linked busybox
(or something of that sort) binary. Dynamically linked binaries may not always
work and it's nice to have something you know to work.

One of the best sources of debugging information is Android's /proc/last_kmsg.
It contains a copy of the previous kernel's /proc/kmsg. Both kernels need to
support it, but probably all Android kernels do. There's a newer alternative to
it in mainline Linux, but if you're running a mainline kernel on a
phone/tablet, you're a very lucky person. It doesn't always work, though. I
have do idea why, unfortunately.

Unfortunately, writes to /dev/kmsg don't seem to show up in /proc/last_kmsg.
:(

A simple option is mounting a partition somewhere and then writing to a file on
that partition. Don't forget to run sync!

You can also compile the kernel with a USB gadget (ethernet is probably the
best), and then start netcat with a shell or telnetd. Remember that busybox's
telnetd needs /dev/pts!

Sample network debugging code:

```bash
mkdir /dev/pts
mount -t devpts none /dev/pts
ifconfig usb0 up
ifconfig usb0 10.0.10.2 netmask 255.255.255.0
ip route add default via 10.0.10.1
```

Client-side config script:

```bash
if ip a | grep "usb0" > /dev/null
then
	USB_IFACE="usb0"
#elif ip a | grep "enp.s..u.u." > /dev/null
else
	USB_IFACE="$(ip a | grep -Eo "enp.s..u.u.(i.)?")"
fi

ip addr add 10.0.10.1/24 dev $USB_IFACE
ip link set up dev $USB_IFACE
iptables -t nat -I POSTROUTING -o wlp2s0 -s 10.0.10.1/24 -j MASQUERADE
iptables -I FORWARD -i $USB_IFACE -s 10.0.10.1/24 -j ACCEPT
iptables -I FORWARD -i wlp2s0 -s 10.0.10.1/24 -j ACCEPT
echo 1 > /proc/sys/net/ipv4/ip_forward
echo 1 > /proc/sys/net/ipv4/conf/wlp2s0/forwarding
```

